/*
 * @Author: 黑白灰01 3193273703@qq.com
 * @Date: 2025-08-29 17:46:50
 * @LastEditors: 黑白灰01 3193273703@qq.com
 * @LastEditTime: 2025-09-01 16:31:13
 * @FilePath: /hei-oa/src/main.ts
 * @Description: 主文件
 */
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { TransformInterceptor } from 'src/common/interceptors/transform.interceptor';
import { HttpExceptionFilter } from 'src/common/filters/http-exception.filter';
import { GlobalDateFormatInterceptor } from './common/interceptors/global-date-format.interceptor';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  // swagger 配置
  // 构建swagger文档
  const options = new DocumentBuilder()
    .setTitle('hei-OA系统接口文档')
    .setVersion('2.0')
    .addTag('应用', '应用基础接口')
    .addTag('用户管理', '用户相关接口')
    .build();
  const document = SwaggerModule.createDocument(app, options);
  // 设置文档路径： eg: localhost:3000/api-docs
  SwaggerModule.setup('/api-docs', app, document);
  // 注册全局拦截器
  app.useGlobalInterceptors(new TransformInterceptor());
  app.useGlobalInterceptors(new GlobalDateFormatInterceptor());

  // 注册全局异常过滤器
  app.useGlobalFilters(new HttpExceptionFilter());
  await app.listen(process.env.PORT ?? 3000);
}
bootstrap();
